<?php
/*
 * employe/edit.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;
use RHX\Helper\Number;
?>
<?php
$title = 'Fiche Employé';
$this->headTitle($title);

// Variables
/**
 * Employé en Cours
 * 
 * @var \RHX\Model\Object\Employe $employe
 */
$employe = $this->employe;
$site	 = $employe->getSite();

$etatCivil	 = array(0	 => '', 1	 => 'Monsieur', 2	 => 'Madame', 3	 => 'Mademoiselle');
$situation	 = array(
    '0'	 => 'Célibataire',
    '1'	 => 'Célibataire',
    '2'	 => 'Marié(e)',
    '3'	 => 'Divorcé(e)',
    '4'	 => 'Veuf(ve)',
);
$niveau		 = array();
$echelon	 = array();
for ($i = 1; $i < 6; $i++) {
    if ($i < 5) {
	$echelon["$i"] = "Echelon $i";
    }
    $niveau["$i"] = "Niveau " . Number::getRomanNumber($i);
}
?>
<div class="content-head">
    <?php $name		 = (is_null($employe->nom2) || ($employe->nom2 == '')) ? $employe->nom1 : $employe->nom2; ?>
    <h3><?php echo $title; ?> : <?php echo $employe->prenom . ' ' . $name . ' - ' . $site->libelle ?></h3>
    <div class="toolbar">
        <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
        <button class='btn' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $site->id, 'other1'	 => 1)) ?>';">Fermer</button>
    </div>
</div>
<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">Etat Civil : <a href="#" id="etatcivil" data-name="civil_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $etatCivil[(int) $employe->civil_id] ?></a></div>

    <div class="empl-top">
        <div class="empl-matricule saumon empl-title">Matricule : <?php echo $employe->getMatricule(true); ?></div>
        <div class="empl-site marron empl-title">
            Site Employeur : <a href="#" id="site" data-name="site_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $site->libelle; ?></a>
        </div>
    </div>

    <div class="empl-left">
        <div class="empl-group">
            <div class="empl-photo">PHOTO</div>
            <div class="empl-full violet" style="text-align: center;">
		Curriculum Vitae<br>
		<a href="<?php echo (strlen($employe->cv_path) < 4) ? '#' : $this->basePath() . $employe->cv_path; ?>">Consulter</a> - <a href="#" data-name="cv_path" data-id="<?php echo $employe->matricule; ?>" id="cv_path">Changer</a>
	    </div>
            <div class="empl-full saumon" style="text-align: center;">
		Code Caisse TC POS<br>
		<a href="#" id="code_caisse" data-type="text" data-pk="<?php echo $employe->matricule; ?>" data-name="code_caisse_tcpos"><?php echo $employe->code_caisse_tcpos; ?></a>
	    </div>
	    <!--	    <div class="empl-full gris" style="text-align: center;">
			    <a href="<?php echo $this->url('RHX/default', array('controller'	 => 'export', 'action'	 => 'ficheEmploye')) ?>">Exporter en Word</a>
			</div>-->
        </div>
    </div>

    <div class="empl-center">

        <div class='empl-group'>
            <div class='empl-full saumon2'>
                Nom d'usage : <a href="#" id="nom" class='uppercase' data-name="nom1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->nom1 ?></a>
            </div>
            <div class='empl-full saumon2'>
                Nom de jeune Fille : <a href="#" id="nom2" class='uppercase' data-name="nom2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->nom2 ?></a>
            </div>
            <div class='empl-full saumon2'>
                Prénom : <a href="#" id="prenom" class='capitalize' data-name="prenom" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->prenom ?></a>
            </div>
        </div>

        <div class="empl-group">
            <div class="empl-full gris">Adresse 1 : <a href="#" id="adresse1" data-name="adresse1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->adresse1 ?></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp1" data-name="cp1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cp1 ?></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville1" data-name="ville1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->ville1 ?></a></div>
            <div class="empl-full gris">Adresse 2 : <a href="#" id="adresse2" data-name="adresse2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->adresse2 ?></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp2" data-name="cp2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cp2 ?></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville2" data-name="ville2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->ville2 ?></a></div>
            <div class="empl-half gris">Téléphone : <a href="#" id="num_mobile" data-name="telephone" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->telephone ?></a></div>
            <div class="empl-half gris">E-mail : <a href="#" id="email" data-name="email" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->email ?></a></div>
        </div>

        <div class="empl-group">
            <div class="empl-full beige">
                Numéro d'immatriculation CPAM : <a href="#" id="num_cpam" data-name="cpam" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cpam ?></a>
            </div>
            <div class="empl-full beige">
                Situation Familiale : <a href="#" id="situation_familiale" data-name="situation_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $situation[$employe->situation_id]; ?></a>
            </div>
            <div class="empl-full beige">
                Nombre d'enfant : <a href="#" id="nombre_enfant" data-name="enfant" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->enfant ?></a>
            </div>
            <div class="empl-full beige">
                Numéro d'immatriculation Pole Emploi : <a href="#" id="num_pole_emploi" data-name="pole_emploi" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->pole_emploi ?></a>
            </div>
        </div>

        <div class='empl-group'>
	    <?php
	    $transport	 = $employe->getTransport();
	    $mutuelle	 = $employe->getMutuelle();
	    ?>
            <div class='empl-half gris'>
                Mutuelle : <a href="#" id="mutuelle" data-name="mutuelle" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $mutuelle->libelle; ?></a>
            </div>
            <div class='empl-half gris-beige'>
                Titre Transport : <a href="#" id="titre_transport" data-name="transport_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $transport->libelle; ?></a>
            </div>
            <div class='empl-half gris'>
		<?php $dateEffet	 = new \DateTime($employe->mutuelle_date_effet); ?>
                Date d'effet : <a href="#" class="rhdatetime" id="date_effet" data-name="mutuelle_date_effet" data-pk="<?php echo $employe->matricule; ?>" data-type="combodate"><?php echo $dateEffet->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_effet" data-name="mutuelle_date_effet" data-pk="<?php echo $employe->matricule; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Véhicule de fonction : <a href="#" id="vehicule_fonction"></a>
            </div>
            <div class='empl-half' style='border: none; margin-right: 2px'></div>
            <div class='empl-half gris-beige'>
                Immatriculation du véhicule : <a href="#" id="immatriculation" data-type="text"><?php echo '' ?></a>
            </div>
	    <?php
	    $visite		 = $employe->getVisiteMedicale();
	    $dateVisite	 = new \DateTime($visite->date_visite);
	    ?>
            <div class='empl-half gris'>
                Date visite médicale : <a class="rhdatetime" href="#" id="date_visite" data-pk="<?php echo $visite->id; ?>" data-name="date_visite" data-type="combodate"><?php echo $dateVisite->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_visite" data-table="rh_employe_sante" data-name="date_visite" data-pk="<?php echo $visite->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Numéro de permis : <a href="#" id="num_permis" data-type="text"><?php echo '' ?></a>
            </div>
        </div>
    </div>
    <div class="empl-right">

        <div class='empl-group'>
            <div class='empl-full gris-beige'>
		<?php $dateNaissance	 = new \DateTime($employe->naissance); ?>
                Date de naissance : <a class="rhdatetime" href="#" id='date_naissance' data-pk="<?php echo $employe->matricule ?>" data-name="naissance" data-type="combodate"><?php echo $dateNaissance->format("d/m/Y"); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_naissance" data-name="naissance" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-full gris-beige'>
                Lieu de naissance : <a href="#" id="lieu_naissance" data-name="naissance_lieu" data-pk="<?php echo $employe->matricule; ?>" data-type="textarea"><?php echo $employe->naissance_lieu ?></a>
            </div>
            <div class='empl-full gris-beige'>
                Pays de naissance : <a href="#" id="pays_naissance" data-name="naissance_pays" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->naissance_pays ?></a>
            </div>
            <div class='empl-full gris-beige'>
                Nationalité : <a href="#" id="nationalite" data-type="text"><?php echo '' ?></a>
            </div>
        </div>

        <div class='empl-group'>
	    <?php
	    $titreSejour	 = $employe->getTitreSejour();
	    ?>
            <div class='empl-full saumon'>
                Type Titre de Séjour : <a href="#" id="titre_sejour" data-name="sejour_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $titreSejour->libelle; ?></a>
            </div>
            <div class='empl-full saumon'>
                Numéro Titre de Séjour : <a href="#" id="num_titre_sejour" data-name="sejour_num" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->sejour_num ?></a>
            </div>
            <div class='empl-full saumon'>
		<?php $finSejour	 = new \DateTime($employe->sejour_fin); ?>
                Fin de validité Titre Séjour : <a class="rhdatetime" href="#" id="date_fin_validite_sejour" data-name="sejour_fin" data-pk="<?php echo $employe->matricule; ?>" data-type="combodate"><?php echo $finSejour->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_fin_validite_sejour" data-name="sejour_fin" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
        </div>

        <div class='empl-group'>
            <div class='empl-full bleu'>
                RIB : <a href="#" id="rib" data-name="rib" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->rib; ?></a>
            </div>
        </div>

	<!-- DIPLOMES ET FORMATIONS -->
        <div class='empl-group'>
	    <!-- DIPLOMES -->
	    <!--<div id="diplomes">-->
	    <?php
	    $diplomes	 = $employe->getDiplomes();
	    $count		 = 0;
	    if (is_array($diplomes)) {
		$count = count($diplomes);
	    }
	    else {
		try {
		    $count = $diplomes->count();
		}
		catch (\Exception $ex) {
		    $count = 0;
		}
	    }
	    ?>
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Diplômes</div>
	    <div id="diplomes">
		<?php if ($count != 0): ?>
		    <?php foreach ($diplomes as $d): ?>
			<?php $diplom = $d->getDiplome(); ?>
			<div class='empl-full violet' id="d<?php echo $diplom->id; ?>"><?php echo $diplom->libelle; ?></div>
		    <?php endforeach; ?>
		<?php else: ?>
    		<div id="diplome-none" class='empl-full violet'>Aucun Diplôme</div>
		<?php endif; ?>
	    </div>
	    <!--	    </div>-->
	    <div class="empl-full">&nbsp;<button class="btn btn-info add-diplome" style="float: right;">Ajouter un Diplôme</button></div>
	    <!-- FORMATIONS -->
	    <!--<div id="formations">-->
	    <?php
	    $formations	 = $employe->getFormations();
	    $counter	 = 0;
	    if (is_array($formations)) {
		$counter = count($formations);
	    }
	    else {
		try {
		    $counter = $formations->count();
		}
		catch (\Exception $ex) {
		    $counter = 0;
		}
	    }
	    ?>
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Formations</div>
	    <div id="formations-list">
		<?php if ($counter != 0): ?>

		    <?php foreach ($formations as $f): ?>
			<?php $form = $f->getFormation(); ?>
			<div class='empl-full vert-olive' id="f<?php echo $form->id; ?>"><?php echo $form->libelle; ?></div>
		    <?php endforeach; ?>

			<?php else: ?>
    			<div id="formation-none" class='empl-full vert-olive'>Aucune Formation Continue</div>
			<?php endif; ?>
	    </div>
	    <!--</div>-->
	    <div class="empl-full">&nbsp;<button class="btn btn-success add-formation" style="float: right;">Ajouter une Formation</button></div>
        </div>

    </div>

    <div style="clear: both"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Fermer</button>
        </div>
    </div>

</div>

<!-- Contrat -->
<?php
// Type de contrat
$contratType	 = $employe->getContratType();
?>
<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">
	<span style="line-height: 32px;">Contrat</span>
	<div style="float: right; margin-right: 10px; position: relative;">
	    <a href="#" title="Ajouter un contrat" class="contrat-add" data-matricule="<?php echo $employe->matricule; ?>">
		<img src="<?php echo $this->basePath() . '/img/rhx/add-32x32.png' ?>">
	    </a>
	    <div class="add-contrat" id="dialog-contrat" style="display: none;">
		<!-- -->
	    </div>
	</div>
    </div>

    <div class="empl-full saumon2 empl-title" style="margin-top: 15px;">
        Type de contrat : <a href="#" id="contrat_type" data-name="contrat_type" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $contratType->libelle; ?></a>
    </div>

    <div class="empl-left" style="width: 50%">

        <div class='empl-group'>
            <div class="empl-full">
<?php $contratDebut	 = new \DateTime($employe->contrat_debut); ?>
                Date d'entrée : <a class="rhdatetime" href='#' id='debut_contrat' data-name="contrat_debut" data-pk="<?php echo $employe->matricule; ?>" data-type='combodate'><?php echo $contratDebut->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="debut_contrat" data-name="contrat_debut" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
	    <?php
	    $entretien	 = $employe->getEntretien();
	    $dateEntretien	 = new \DateTime($entretien->date_entretien);
	    ?>
            <div class="empl-full">
                Date dernier entretien individuel : <a href='#' id='entretien' data-name='date_entretien' data-pk='<?php echo $entretien->id; ?>' data-type='combodate'><?php echo $dateEntretien->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="entretien" data-name="entretien" data-table="rh_employe_entretien" data-pk="<?php echo $entretien->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
        </div>

    </div>

    <div class="empl-right" style="width: 49%">
	<?php $motif		 = $employe->getMotif(); ?>
        <div class='empl-group'>
            <div class='empl-full gris'>
<?php $dateDepart	 = new \DateTime($employe->contrat_fin); ?>
                Date départ : <a class="rhdatetime" href='#' id='fin_contrat' data-name="contrat_fin" data-pk="<?php echo $employe->matricule; ?>" data-type='combodate'><?php echo $dateDepart->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="fin_contrat" data-name="contrat_fin" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-full gris'>
                Motif départ : <a href='#' id='depart_motif' data-type='select' data-name="contrat_motif_depart" data-pk="<?php echo $employe->matricule; ?>"><?php echo $motif->libelle; ?></a>
            </div>
        </div>
    </div>

    <!-- Avenant -->
    <?php
    $avenant	 = $employe->getAvenant();
    $poste		 = $employe->getPoste();
    ?>
    <div class="empl-full bleu empl-title">
        <span style='line-height: 20px'>
            Avenants &nbsp;
            <div class="toolbox">
                <a href="#" id="avenantNewButton" onclick="return addAvenant();">
                    <img src="<?php echo $this->basePath() . '/img/foam/add.png' ?>" alt="Ajouter un Avenant" title="Ajouter un nouvel Avenant">
                </a>&nbsp;
<?php if ((int) $avenant->id != 0): ?>
		<a href="#" id="avenantEditButton" onclick="return editAvenant();">
    		    <img src="<?php echo $this->basePath() . '/img/rh/edit-32x32.png' ?>" alt="Editer l'avenant" title="Editer l'Avenant en cours">
    		</a>
		<?php endif ?>
		<a href="#" id="avenantCancelButton" onclick="return cancelAvenantChange();">
		    <img src="<?php echo $this->basePath() . '/img/rhx/cancel-32x32.png' ?>" alt="Editer l'avenant" title="Annuler">
		</a>
            </div>
        </span>
	<span style="line-height: 20px; margin-left: 50px; font-size: 1.5em; color: #ffffff;" id="avenant-name"></span>
    </div>

    <div class="empl-left empl-highlight" style="width: 50%">

	<!-- EDITION AVENANT -->
        <div class="empl-group" id="posteEdit">
            <div class="empl-full empl-saumon">
                Poste : <a href='#' id='poste' data-name="poste_id" data-pk="<?php echo $avenant->id ?>" data-type='select' onclick='return false;'><?php echo $poste->libelle ?></a>
            </div>
	    <?php
	    $college = new \RHX\Model\Object\College();
	    if ($avenant) {
		$college = $avenant->getCollege();
	    }
	    ?>
            <div class="empl-full empl-saumon">
                Collège : <a href='#' id='college' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="college"><?php echo $college->libelle; ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Niveau : <a href='#' id='niveau' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="niveau">Niveau <?php echo Number::getRomanNumber($avenant->niveau); ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Echelon : <a href='#' id='echelon' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="echelon">Echelon <?php echo $avenant->echelon ?></a>
            </div>
        </div>

	<!-- NOUVELLE AVENANT POSTE -->
	<div class="empl-group" id="posteNew" style="display: none;">
            <div class="empl-full empl-saumon">
                Poste : <a href='#' id='posteNeo' data-type='select' onclick='return false;'><?php echo $poste->libelle ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Collège : <a href='#' id='collegeNeo' data-type='select' onclick='return false;'><?php echo $college->libelle; ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Niveau : <a href='#' id='niveauNeo' data-type='select' onclick='return false;'>Niveau I</a>
            </div>
            <div class="empl-full empl-saumon">
                Echelon : <a href='#' id='echelonNeo' data-type='select' onclick='return false;'>Echelon 1</a>
            </div>
        </div>
    </div>

    <div class="empl-right empl-highlight" style="width: 49%">
        <div class="empl-group" id="avenantEdit">
            <div class="empl-full empl-jaune">
                Contrat horaire hebdomadaire : <a href='#' id='horaire_hebdo' data-name="hebdo" data-pk="<?php echo $avenant->id; ?>" data-type='text' onclick='return false;'><?php echo $avenant->hebdo ?></a> heures
            </div>
            <div class="empl-full empl-jaune">
                Taux horaire : <a href='#' id='horaire_taux' data-name="taux" data-pk="<?php echo $avenant->id; ?>"  data-type='text' onclick='return false;'><?php echo $avenant->taux ?></a> €
            </div>
            <div class="empl-full empl-gris">
				<?php $debutAvenant = new \DateTime($avenant->debut); ?>
                Début de l'Avenant : <a href="#" id="avenant_debut" data-name="debut" data-pk="<?php echo $avenant->id; ?>"  data-type="combodate" onclick='return false;'><?php echo $debutAvenant->format('d/m/Y'); ?></a>
            </div>
            <div class="empl-full empl-gris">
		<?php
		if ($avenant->fin == '0000-00-00') {
		    $avenant->fin = '2015-12-31';
		}
		$finAvenant	 = new \DateTime($avenant->fin);
		?>
                Fin de l'Avenant : <a class="rhdatetime" href="#" id="avenant_fin" data-name="fin" data-pk="<?php echo $avenant->id; ?>"  data-type="combodate" onclick='return false;'><?php echo $finAvenant->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="avenant_fin" data-table="rh_avenant" data-name="fin" data-pk="<?php echo $avenant->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
        </div>
	<!-- NOUVELLE AVENANT -->
	<?php
	$debut		 = new RHDateTime($avenant->debut);
	$debut->modify('next day');
	?>
	<div class="empl-group" id="avenantNew" style="display: none;">
            <div class="empl-full empl-jaune">
                Contrat horaire hebdomadaire : <a href='#' id='hebdo' data-type='text' onclick='return false;'>00.0</a> heures
            </div>
            <div class="empl-full empl-jaune">
                Taux horaire : <a href='#' id='taux' data-name="taux" data-type='text' onclick='return false;'>00.0</a> €
            </div>
            <div class="empl-full empl-gris">
                Début de l'Avenant : <a href="#" id="debut" data-name="debut" data-type="combodate" onclick='return false;'><?php echo $debut->date('d/m/Y'); ?></a>
            </div>
            <div class="empl-full empl-gris">
                Fin de l'Avenant : <a class="rhdatetime" href="#" id="fin" data-type="combodate" onclick='return false;'>00/00/0000</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="fin" data-name="fin" data-pk="<?php echo $avenant->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
	    <form id="avenantNewForm" action="#" method="post">
		<input type="hidden" name="matricule" value="<?php echo $employe->matricule; ?>">
		<input type="hidden" name="poste_id" id="data-poste" value="<?php echo $poste->id; ?>">
		<input type="hidden" name="hebdo" id="data-hebdo" value="0.0">
		<input type="hidden" name="taux" id="data-taux" value="0.0">
		<input type="hidden" name="debut" id="data-debut" value="<?php echo $debut->date(); ?>">
		<input type="hidden" name="fin" id="data-fin" value="0000-00-00">
		<input type="hidden" name="niveau" id="data-niveau" value="1">
		<input type="hidden" name="echelon" id="data-echelon" value="1">
		<input type="hidden" name="college" id="data-college" value="1">
	    </form>
        </div>
    </div>

    <div class="empl-full"><button class="btn btn-primary" id="avenantAddButton" style="display: none;" onclick="return AddNewAvenant();">Enregistrer</button></div>

    <div class='empl-full bleu-navy' style="clear: both" id='avenant-message'>
	<span>&nbsp;</span>
    </div>

    <div class="empl-center" style="margin-top: -15px; width: 70%;">
        <div class="empl-group">
            <div class="empl-full vert-olive">
                <a href='#' onclick='return avenantHistory(<?php echo $employe->matricule ?>);' style='font-weight: bolder'>
		    AVENANTS (historique)
		</a>
            </div>
	    <?php
	    $history	 = $employe->getAvenantHistory();
	    //var_dump($history);
	    $count		 = is_array($history) ? count($history) : $history->count();
	    $count--;
	    ?>
	    <?php $k		 = 0 ?>
	    <?php foreach ($history as $story): ?>
		<?php
		$av	 = $story->getAvenant();
		$pos	 = $av->getPoste();
		//if(++$count > 3) break;
		?>
	    <div class='empl-half gris-beige' style='width: 24%'>
		    <?php $nommage = ($count == 0 ) ? 'Contrat' : 'Avenant #' . $count; ?>
		    <?php if ($k == 0): ?><b><?php endif ?>
    		    <a class="full-link" href='#' id="av-<?php echo $av->id; ?>" onclick='return avenantDetails(<?php echo $av->id ?>, "<?php echo $nommage; ?>");'><?php echo $nommage; ?></a>
			<?php if ($k == 0): ?></b><?php endif ?>
    	    </div>
    	    <div class="empl-half gris-beige" style='width: 49%'>
		    <?php if ($k == 0): ?><b><?php endif ?>
    		    <a class="full-link" href='#' onclick='return avenantDetails(<?php echo $av->id ?>, "<?php echo $nommage; ?>");'><?php echo $pos->libelle ?></a>
			<?php if ($k == 0): ?></b><?php endif ?>
    	    </div>
    	    <div class="empl-half gris-beige" style="width: 24%">
		    <?php if ($k == 0): ?><b><?php endif ?>
			<?php $debutAvenant = new RHDateTime($av->debut); ?>
    		    <a class="full-link" href='#' onclick='return avenantDetails(<?php echo $av->id ?>, "<?php echo $nommage; ?>");'><?php echo $debutAvenant->date('d/m/Y'); ?></a>
			<?php if ($k == 0): ?></b><?php endif ?>
    	    </div>
		<?php
		$k++;
		$count--;
		?>
	    	    <?php endforeach; ?>
            <div class="empl-full vert-olive">
                &nbsp;
            </div>
        </div>
    </div>

    <div style="clear: both"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Fermer</button>
        </div>
    </div>

</div>

<div class="empl-center" style="width: 30%">
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Transmission de la fiche à ADEC</a></div>
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Impression Attestation Employeur</a></div>
</div>

<!-- Disponibilité -->
<?php
$disponibilite	 = $employe->getDisponibilite();
//var_dump($employe);
//var_dump($disponibilite);
?>
<div class="empl-border" style='margin-top: 15px'>
    <div class="empl-full bleu empl-title" style='margin-bottom: 10px'>Disponibilité</div>

    <div class="list-container">
        <table class="table table-striped list-table">
            <thead>
                <tr>
                    <td></td>
                    <td class='empl-title' style='text-align: center'>Disponibilité</td>
                    <td class='empl-title' style='text-align: center'>Heure d'arrivée</td>
                    <td class='empl-title' style='text-align: center'>Heure de départ</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Lundi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="lundi" data-type="select" data-name="lundi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->lundi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="lundi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="lundi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->lundi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
			<a class="full-link" href="#" id="lundi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="lundi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->lundi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Mardi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi" data-type="select" data-name="mardi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->mardi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mardi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mardi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mardi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mardi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Mercredi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi" data-type="select" data-name="mercredi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->mercredi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mercredi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mercredi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mercredi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mercredi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Jeudi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi" data-type="select" data-name="jeudi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->jeudi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="jeudi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->jeudi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="jeudi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->jeudi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Vendredi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi" data-type="select" data-name="vendredi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->vendredi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="vendredi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->vendredi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="vendredi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->vendredi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Samedi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi" data-type="select" data-name="samedi" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->samedi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="samedi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->samedi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="samedi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->samedi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Dimanche</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche" data-type="select" data-name="dimanche" data-pk="<?php echo $disponibilite->id ?>">
<?php echo ((int) $disponibilite->dimanche == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="dimanche_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->dimanche_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="dimanche_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->dimanche_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
            </tbody>

        </table>
    </div>

    <div style="clear: both; height: 2em;"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Fermer</button>
        </div>
    </div>
</div>

<div id='avenant-dialog'></div>

<script type="text/javascript">
	    // Démarrage
	    $(document).ready(function() {
		$('#etatcivil').editable({
		    title: 'Etat Civil',
		    showbuttons: false,
		    value: <?php echo $employe->civil_id ?>,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonetatcivillist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			etatCivil = value;
			$("#data-etat_civil_id").val(value);
		    }
		});
		$('#site').editable({
		    title: "Site Employeur",
		    showbuttons: false,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			site = value;
			$('#data-site_id').val(value);
		    }
		});
		$('#nom').editable({
		    title: "Nom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>/1",
		    validate: function(value) {
			nom = value;
			$('#data-nom').val(value.toUpperCase());
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
		$('#nom2').editable({
		    title: "Nom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>/1",
		    validate: function(value) {
			nom2 = value;
			$('#data-nom2').val(value.toUpperCase());
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
		$('#prenom').editable({
		    title: "Prénom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			prenom = value;
			$('#data-prenom').val(value);
		    },
		    inputclass: 'capitalize',
		    params: function(params) {
			value = params.value;
			capitalize = toTitleCase(value);
			params.value = capitalize;
			return params;
		    }
		});
		$('#num_mobile').editable({
		    title: "Numéro du téléphone Mobile",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_mobile = value;
			$('#data-num_mobile').val(value);
		    }
		});
		$('#email').editable({
		    title: "Adresse Email",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			email = value;
			$('#data-email').val(value);
		    }
		});
		$('#adresse1').editable({
		    title: "Adresse",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			adresse1 = value;
			$('#data-adresse1').val(value);
		    }
		});
		$('#adresse2').editable({
		    title: "Adresse",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			adresse2 = value;
			$('#data-adresse2').val(value);
		    }
		});
		$('#cp1').editable({
		    title: "Code Postal",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			cp1 = value;
			$('#data-cp1').val(value);
		    }
		});
		$('#cp2').editable({
		    title: "Code Postal",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			cp2 = value;
			$('#data-cp2').val(value);
		    }
		});
		$('#ville1').editable({
		    title: "Ville",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			ville1 = value;
			$('#data-ville1').val(value);
		    }
		});
		$('#ville2').editable({
		    title: "Ville",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			ville2 = value;
			$('#data-ville2').val(value);
		    }
		});
		$('#num_cpam').editable({
		    title: "Numéro CPAM",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_cpam = value;
			$('#data-num_cpam').val(value);
		    }
		});
		$('#situation_familiale').editable({
		    title: "Situation familiale",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonsituationlist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			situation_familiale = value;
			$('#data-situation_familiale').val(value);
		    }
		});
		$('#nombre_enfant').editable({
		    title: "Nombre d'enfant",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			nb_enfant = value;
			$('#data-nb_enfant').val(value);
		    }
		});
		$('#num_pole_emploi').editable({
		    title: "Numéro Pole Emploi",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_pole_emploi = value;
			$('#data-num_pole_emploi').val(value);
		    }
		});
		$('#mutuelle').editable({
		    title: "Mutuelle",
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'mutuelleList')) ?>',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			mutuelle = value;
			$('#data-mutuelle').val(value);
		    }
		});
		$('#titre_transport').editable({
		    title: "Titre de transport",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsontransportlist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			titre_transport = value;
			$('#data-transport_id').val(value);
		    }
		});
		$('#date_effet').editable({
		    title: "Date d'effet",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#vehicule_fonction').editable({
		    title: "Véhicule de fonction",
		    validate: function(value) {
			vehicule_fonction = value;
			$('#data-vehicule_fonction').val(value);
		    }
		});
		$('#immatriculation').editable({
		    title: "Immatriculation du véhicule",
		    validate: function(value) {
			immatriculation = value;
			$('#data-immatriculation').val(value);
		    }
		});
		$('#date_visite').editable({
		    title: "Dernière Date de visite Médicale",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeSanteData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#num_permis').editable({
		    title: "Numéro du Permis de conduire",
		    validate: function(value) {
			num_permis = value;
			$('#data-num_permis').val(value);
		    }
		});
		$('#date_naissance').editable({
		    title: 'Date de naissance',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#lieu_naissance').editable({
		    title: "Lieu de naissance",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			lieu_naissance = value;
			$('#data-lieu_naissance').val(value);
		    }
		});
		$('#pays_naissance').editable({
		    title: "Pays de naissance",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			pays_naissance = value;
			$('#data-pays_naissance').val(value);
		    }
		});
		$('#nationalite').editable({
		    title: "Nationalité",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			nationalite = value;
			$('#data-nationalite').val(value);
		    }
		});
		$('#titre_sejour').editable({
		    title: "Titre de Séjour",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'sejourList')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			titre_sejour = value;
			$('#data-titre_sejour').val(value);
		    }
		});
		$('#num_titre_sejour').editable({
		    title: "Numéro du titre de Séjour",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			num_titre_sejour = value;
			$('#data-num_titre_sejour').val(value);
		    }
		});
		$('#date_fin_validite_sejour').editable({
		    title: 'Date de Fin de Séjour',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#rib').editable({
		    title: "RIB",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			rib = value;
			$('#data-rib').val(value);
		    }
		});
		// Contrat
		$('#contrat_type').editable({
		    title: 'Type de contrat',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'contratList')) ?>",
		    validate: function(value) {
			$('#data-contrat_type_id').val(value);
		    }
		});
		$('#debut_contrat').editable({
		    title: 'Début de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#fin_contrat').editable({
		    title: 'Fin de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#depart_motif').editable({
		    title: 'Motif de départ',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>',
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonMotifList')) ?>',
		    validate: function(value) {
			depart_motif = value;
			$('#data-depart_motif').val(value);
		    }
		});

		// Disponibilite
		$('#lundi_entree').editable({
		    placement: 'right',
		    format: 'HH:mm',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_entree').val(val);
		    }
		});
		$('#mardi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_entree').val(val);
		    }
		});
		$('#mercredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_entree').val(val);
		    }
		});
		$('#jeudi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_entree').val(val);
		    }
		});
		$('#vendredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_entree').val(val);
		    }
		});
		$('#samedi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_entree').val(val);
		    }
		});
		$('#dimanche_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_entree').val(val);
		    }
		});
		//
		$('#lundi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_sortie').val(val);
		    }
		});
		$('#mardi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_sortie').val(val);
		    }
		});
		$('#mercredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_sortie').val(val);
		    }
		});
		$('#jeudi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_sortie').val(val);
		    }
		});
		$('#vendredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_sortie').val(val);
		    }
		});
		$('#samedi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_sortie').val(val);
		    }
		});
		$('#dimanche_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_sortie').val(val);
		    }
		});
		//
		$('#dimanche').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-dimanche').val(value);
			//alert(value);
			if (value == 0) {
			    $("#dimanche_entree").text("00:00");
			    $("#data-dimanche_entree").val("00:00");
			    $("#dimanche_sortie").text("00:00");
			    $("#data-dimanche_sortie").val("00:00");
			}
		    }
		});
		$('#lundi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-lundi').val(value);
			if (value == 0) {
			    $("#lundi_entree").text("00:00");
			    $("#data-lundi_entree").val("00:00");
			    $("#lundi_sortie").text("00:00");
			    $("#data-lundi_sortie").val("00:00");
			}
		    }
		});
		$('#mardi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-mardi').val(value);
			if (value == 0) {
			    $("#mardi_entree").text("00:00");
			    $("#data-mardi_entree").val("00:00");
			    $("#mardi_sortie").text("00:00");
			    $("#data-mardi_sortie").val("00:00");
			}
		    }
		});
		$('#mercredi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-mercredi').val(value);
			if (value == 0) {
			    $("#mercredi_entree").text("00:00");
			    $("#data-mercredi_entree").val("00:00");
			    $("#mercredi_sortie").text("00:00");
			    $("#data-mercredi_sortie").val("00:00");
			}
		    }
		});
		$('#jeudi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-jeudi').val(value);
			if (value == 0) {
			    $("#jeudi_entree").text("00:00");
			    $("#data-jeudi_entree").val("00:00");
			    $("#jeudi_sortie").text("00:00");
			    $("#data-jeudi_sortie").val("00:00");
			}
		    }
		});
		$('#vendredi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-vendredi').val(value);
			if (value == 0) {
			    $("#vendredi_entree").text("00:00");
			    $("#data-vendredi_entree").val("00:00");
			    $("#vendredi_sortie").text("00:00");
			    $("#data-vendredi_sortie").val("00:00");
			}
		    }
		});
		$('#samedi').editable({
		    title: "Disponibilité",
		    source: [{value: 0, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-samedi').val(value);
			if (value == 0) {
			    $("#samedi_entree").text("00:00");
			    $("#data-samedi_entree").val("00:00");
			    $("#samedi_sortie").text("00:00");
			    $("#data-samedi_sortie").val("00:00");
			}
		    }
		});

		// Ajouter un Diplome
		$('.add-diplome').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectDiplome')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Diplômes",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250}
			});
		    });
		    ajax.fail(function() {
			alert("Une erreur est survenue lors du chargement des diplômes !");
		    });
		});
		// Ajouter un Formation
		$('.add-formation').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectFormation')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Formations",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250}
			});
		    });
		    ajax.fail(function() {
			alert("Une erreur est survenue lors du chargement des formations !");
		    });
		});
		// CODE Caise TC POS
		$('#code_caisse').editable({
		    title: 'Saisie du Code Caisse',
		    url: '<?php echo $this->url("RHX/default", array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>'
		});
		// CV
		$('#cv_path').click(function(e) {
		    // Ouverture de la boite de dialogue
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'dialogUpload')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).dialog({
			    title: 'Upload de Fichier PDF',
			    width: 600,
			    height: 400,
			    autoOpen: true,
			    modal: true
			});
		    });
		});

		// Entretien Individuel
		$('#entretien').editable({
		    title: "Date de l'entretien individuel",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeEntretienData')) ?>',
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});

		// Au click select
		$('.clickSelect').click(function() {
		    this.select();
		});

		// RHDateTime
		$('.rhdatetime').each(function() {
		    text = $(this).text();
		    result = isValideDateRH(text);
		    if (!result) {
			$(this).text("N/A");
		    }
		});

		// Effacer les dates
		$('.cancel-date').click(function(e) {
		    e.preventDefault();
		    if (!confirm("Voulez-vous effacer la date ?")) {
			return false;
		    }
		    id = $(this).attr('data-id');
		    name = $(this).attr('data-name');
		    value = '0000-00-00';
		    table = $(this).attr('data-table');
		    pk = $(this).attr('data-pk');
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'cancelDate')) ?>',
			data: '&id=' + id + '&pk=' + pk + '&name=' + name + '&value=' + value + '&table=' + table
		    });
		    ajax.done(function(result) {
			if (result.done) {
			    $('#' + id).text("N/A");
			} else {
			    // $('#' + id).text('ERREUR');
			    // alert("Erreur");
			}
		    });
		});

		// Ajout Contrat
		$('.contrat-add').click(function(e) {
		    e.preventDefault();
		    matricule = $(this).attr('data-matricule');
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'showContratMenu')) ?>',
			data: '&matricule=' + matricule
		    });
		    ajax.done(function(data) {
			$('#dialog-contrat').hide().html(data).show('normal');
		    });
		});

		// Détecter clic en dehors du DIV
//		$(document).mouseup(function(e) {
//		    var container = $("#dialog-contrat");
//		    if (container.has(e.target).length === 0) { 			    // Masquage du DIV
//			container.hide('normal');
//		    }
//		});
	    });

	    function isValidDate(d) {
		var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
		return d.match(dateRegEx);
	    }

	    function isValideDateRH(d) {
		length = d.length;
		if (length > 10) {
		    return false;
		}
		return true;
	    }

	    function save()
	    {
		date_naissance = $("#date_naissance").val();
		date_fin_validite_sejour = $("#date_fin_validite_sejour").val();
		date_effet = $("#date_effet").val();

		var data = $('#formData').serialize();
		//data += "&date_naissance=" + date_naissance + "&date_effet=" + date_effet + "&date_fin_sejour=" + date_fin_validite_sejour;
		var ajax = $.ajax({
		    type: 'post',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveedit', 'id'		 => $employe->matricule)) ?>",
		    data: data
		});
		ajax.success(function() {
		    location.href = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id)) ?>";
		});
		ajax.error(function() {
		    alert("Une erreur est survenue");
		});
	    }

	    function dump(obj) {
		var out = '';
		for (var i in obj) {
		    out += i + ": " + obj[i] + "\n";
		}

		alert(out);
	    }

	    function addAvenant()
	    {
		// Ask if the user really want to create new Avenant
		var conf = confirm("Voulez-vous créer un nouvel Avenant ?");
		if (!conf)
		    return false;
		// New Amendemnt
		$('#new-avenant').val(1);
		var annuler = "Cliquer ici pour <a href='#' onclick='return cancelNewAvenant();'>Fermer</a>";
		$('#avenant-message').show('slow').html("<span>Un nouvel avenant sera créer à l'enregistrement des informations en cours</span>. " + annuler);

		// Masquage des Edition, Affichage des Nouveaux
		$('#posteEdit').hide('normal', function() {
		    $('#posteNew').show('normal');
		    // Rendre éditable
		    $('#posteNeo').editable({
			title: "Edition du Nouveau Poste",
			source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
			validate: function(value) {
			    $("#data-poste").val(value);
			    // Get JSON
//			    json = $.getJSON('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonPosteData')); ?>/' + value, function(data) {
//				$('#collegeNeo').text(data.college);
//				$('#niveauNeo').text(data.niveau);
//				$('#echelonNeo').text(data.echelon);
//			    });
			}
		    });
		});
		$('#niveauNeo').editable({
		    title: "Edition du NIveau",
		    source: '<?php echo json_encode($niveau); ?>',
		    validate: function(value){
			$('#data-niveau').val(value);
		    }
		});
		$('#echelonNeo').editable({
		    title: "Edition de l'échelon",
		    source: '<?php echo json_encode($echelon); ?>',
		    validate: function(value){
			$('#data-echelon').val(value);
		    }
		});
		$("#collegeNeo").editable({
		    title: "Edition du collège",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'collegeList')); ?>",
		    validate: function(value){
			$('#data-college').val(value);
		    }
		});
		$('#avenantEdit').hide('normal', function() {
		    $('#avenantNew').show('normal');
		    // Rendre éditable
		    $('#hebdo').editable({
			title: "Modification de l'Heure Hedbomadaire",
			validate: function(value) {
			    $('#data-hebdo').val(value);
			},
			inputclass: 'clickSelect',
			tpl: '<input type="text" onclick="select();" onmouseover="select();">'
		    });
		    $('#taux').editable({
			title: "Modification du Taux Horaire",
			validate: function(value) {
			    $('#data-taux').val(value);
			},
			inputclass: 'clickSelect',
			tpl: '<input type="text" onclick="select();" onmouseover="select();">'
		    });
		    $('#debut').editable({
			title: "Date de Début de l'Avenant",
			format: 'DD/MM/YYYY',
			template: 'D / MMMM / YYYY',
			placement: 'left',
			//url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
			validate: function(value) {
			    var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			    $('#data-debut').val(val);
			},
			params: function(params) {
			    value = params.value;
			    date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			    params.value = date.format('YYYY-MM-DD');
			    return params;
			}
		    });
		    $('#fin').editable({
			title: "Date de Fin de l'Avenant",
			format: 'DD/MM/YYYY',
			template: 'D / MMMM / YYYY',
			placement: 'left',
			//url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
			validate: function(value) {
			    var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			    $('#data-fin').val(val);
			},
			params: function(params) {
			    value = params.value;
			    date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			    params.value = date.format('YYYY-MM-DD');
			    return params;
			}
		    });
		});
		// Bouton d'ajout
		$('#avenantAddButton').show(1000);
		// Masquage des boutons
		$('#avenantNewButton').hide('normal');
		$('#avenantEditButton').hide('normal');
		// Changement de couleur
		$('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
		$('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
		$('.empl-gris').removeClass('empl-gris').addClass('gris');

		return false;
	    }

	    function cancelNewAvenant()
	    {
		$('#new-avenant').val(0);
		$('#avenant-message').html('<span></span>');

		return false;
	    }

	    function avenantHistory(employeId)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenant')) ?>/" + employeId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: "Historique des avenants pour <?php echo $name ?>",
			width: 800,
			height: 600,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700}
		    });
		});
		ajax.error(function() {
		    alert("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function avenantDetails(avenantId, title)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenantdetails')) ?>/" + avenantId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url,
		    data: '&title=' + encodeURI(title)
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: title,
			width: 480,
			height: 480,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700}
		    });
		});
		ajax.error(function() {
		    alert("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function editAvenant()
	    {
		// It makes the avenant fields editable
		var conf = confirm("Voulez-vous Editer l'Avenant en cours ?");
		if (conf != true)
		    return false;

		makeEditable();

		return false;
	    }

	    function makeEditable() {
		//alert('Make editable');
		// Changement de couleur
		$('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
		$('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
		$('.empl-gris').removeClass('empl-gris').addClass('gris');
		// Highlight
		setTimeout(function() {
		    $('.empl-highlight').effect('highlight', 'slow');
		}, 1000);
		// Masquage des Boutons
		$('#avenantNewButton').hide('normal');
		$('#avenantEditButton').hide('normal');
		// Affichage du Nom de l'avenant
		$('#avenant-name').hide().html($('#av-<?php echo $avenant->id; ?>').text()).fadeIn('normal');
		if ($('#av-<?php echo $avenant->id; ?>').length === 0) {
		    $('#avenant-name').hide().html("Contrat").fadeIn('normal');
		}

		$('#poste').editable({
		    title: 'Poste',
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			poste = value;
			$('#data-poste_id').val(value);
//			// Get JSON
//			json = $.getJSON('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonPosteData')); ?>/' + poste, function(data) {
//			    $('#college').text(data.college);
//			    $('#niveau_').text(data.niveau);
//			    $('#echelon_').text(data.echelon);
//			});
		    }
		});
		$('#niveau').editable({
		    title: 'Niveau',
		    source: '<?php echo json_encode($niveau); ?>',
		    url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#echelon').editable({
		    title: 'Echelon',
		    source: '<?php echo json_encode($echelon); ?>',
		    url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#college').editable({
		    title: 'Collège',
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'collegeList')); ?>',
		    url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#horaire_hebdo').editable({
		    title: 'Horaire Hebdomadaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_hebdo = value;
			$('#data-horaire_hebdo').val(value);
		    },
		    inputclass: 'clickSelect',
		    tpl: '<input type="text" onclick="select();" onmouseover="select();">'
		});
		$('#horaire_taux').editable({
		    title: 'Taux Horaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_taux = value;
			$('#data-horaire_taux').val(value);
		    },
		    inputclass: 'clickSelect',
		    tpl: '<input type="text" onclick="select();" onmouseover="select();">'
		});
		$('#avenant_debut').editable({
		    title: "Date de début de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-debut_avenant').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
		$('#avenant_fin').editable({
		    title: "Date de fin de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-fin_avenant').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});
	    }

	    function AddNewAvenant() {
		ajax = $.ajax({
		    type: 'post',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addNewAvenant')) ?>',
		    data: $('#avenantNewForm').serialize()
		});
		ajax.success(function() {
		    location.reload();
		});
		ajax.error(function() {
		    alert("Erreur");
		});
	    }

	    function cancelAvenantChange() {
		window.location.reload();
		// On remet le tout à l'état initial
		$('#posteEdit .saumon').removeClass('saumon').addClass('empl-saumon');
		$('#avenantEdit .jaune').removeClass('jaune').addClass('empl-jaune');
		$('#avenantEdit .gris').removeClass('gris').addClass('empl-gris');

		$('#poste').editable('toggleDisabled');
		$('#horaire_hebdo').editable('toggleDisabled');
		$('#horaire_taux').editable('toggleDisabled');
		$('#avenant_debut').editable('toggleDisabled');
		$('#avenant_fin').editable('toggleDisabled');

		$('#posteEdit').show('fast');
		$('#avenantEdit').show('fast');

		$('#posteNew').hide();
		$('#avenantNew').hide();

		$('#avenantAddButton').hide();

		// Affichage des 2 boutons d'ajout et d'édition
		$('#avenantNewButton').show('normal');
		$('#avenantEditButton').show('normal');

		// Masquage du Nom de
		$('#avenant-name').hide('normal');

		return false;
	    }

	    function toTitleCase(str) {
		return str.replace(/\w\S*/g, function(txt) {
		    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
		});
	    }
</script>
<style type="text/css">
    #nom, #nom2{
	text-transform: uppercase;
    }
    .uppercase{
	text-transform: uppercase;
    }
    .capitalize{
	text-transform: capitalize;
    }
    .cancel-icon{
	position: absolute;
	top: 1px;
	right: 4px;
    }
    .add-contrat{
	position: absolute;
	right: 16px;
	top: 25px;
	width: 650px;
	min-height: 100px;
	background: #fff;
	z-index: 99;
	border-radius: 10px 0px 10px 10px;
	box-shadow: 0px 3px 5px 2px #a7a7a7;
	border: solid 1px #707070;
	padding: 10px;
    }
</style>